import logging
from config.config import load_config
from pipeline.tasks import app as celery_app
from pipeline.utils import check_mlserver_connection

def main():
    # Load configurations
    fnsa_inference_config, etcd_host, etcd_port = load_config()
    
    # Initialize logger
    logging.basicConfig(level=fnsa_inference_config.log_level)
    logger = logging.getLogger(__name__)
    
    if not check_mlserver_connection():
        logger.error("ML server is not accessible. Exiting...")
        return
    
    logger.info("Starting fnsa-inference-manager...")
    
    # Start Celery beat
    celery_app.conf.beat_schedule = {
        'process-feeds-every-10-seconds': {
            'task': 'pipeline.tasks.process_feeds',
            'schedule': fnsa_inference_config.jobs_interval_seconds,
        },
    }
    celery_app.conf.timezone = 'UTC'
    celery_app.start()

if __name__ == "__main__":
    main()